home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # MultiFinder-Aware Simple Sample Application
- #
- #
- ------------------------------------------------------------------------------*/
-
-
- #include <Values.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <Desk.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <SegLoad.h>
- #include <Files.h>
- #include <OSUtils.h>
- #include <OSEvents.h>
- #include <DiskInit.h>
- #include <Packages.h>
- #include <String.h>
- #include <Traps.h>
- #include <Threads.h>
- #include <stdio.h>
- #include <strings.h>
-
- #include "TrafficLight.h" /* bring in all the #defines for Sample */
-
-
- struct OurWindowInfoRec {
- Boolean stopped;
- Boolean timeToClose;
- ThreadID threadID;
- };
-
- typedef struct OurWindowInfoRec OurWindowInfoRec;
- typedef OurWindowInfoRec *OurWindowInfoRecPtr;
-
-
- SysEnvRec gMac; /* set up by Initialize */
-
- Boolean gInBackground; /* maintained by Initialize and DoEvent */
-
- Rect gStopRect; /* set up by Initialize */
- Rect gGoRect; /* set up by Initialize */
-
- /* Dhrystone stuff */
- Rec_Pointer Ptr_Glob, Next_Ptr_Glob;
- int Int_Glob;
- Boolean Bool_Glob;
- char Ch_1_Glob, Ch_2_Glob;
- int Arr_1_Glob [50];
- int Arr_2_Glob [50] [50];
-
- Boolean DhrystoneDone;
- DialogPtr DhrystoneDialog;
- int DhrystoneCount;
- ThreadID gDhrystoneThreadID;
- float Microseconds, Dhrystones_Per_Second;
-
- void Proc_1(Rec_Pointer Ptr_Val_Par);
- void Proc_2(One_Fifty *Int_Par_Ref);
- void Proc_3(Rec_Pointer *Ptr_Ref_Par);
- void Proc_4(void);
- void Proc_5(void);
- void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
- void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
- void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val);
- Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
- Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
- Boolean Func_3(Enumeration Enum_Par_Val);
- pascal void * DhrystoneThread(void *threadParam);
- void Dhrystone(void);
-
-
- void EventLoop( void );
- void DoEvent( EventRecord *event );
- void AdjustCursor( Point mouse, RgnHandle region );
- void GetGlobalMouse( Point *mouse );
- void DoUpdate( WindowPtr window );
- void DoActivate( WindowPtr window, Boolean becomingActive );
- void DoContentClick( WindowPtr window );
- void DrawWindow( WindowPtr window );
- void AdjustMenus( void );
- void DoMenuCommand( long menuResult );
- void SetLight( WindowPtr window, Boolean newStopped );
- void DoCloseWindow( WindowPtr window );
- void DoNewWindow(void);
- pascal void * WindowThread(void *myWindow);
- void Terminate( void );
- void Initialize( void );
- Boolean GoGetRect( short rectID, Rect *theRect );
- void ForceEnvirons( void );
- Boolean IsAppWindow( WindowPtr window );
- Boolean IsDAWindow( WindowPtr window );
- Boolean TrapAvailable( short tNumber, TrapType tType );
- void AlertUser( void );
- void AlertUserContinue(short error);
- void MemClear(void *, unsigned long);
-
-
- /* Define HiWrd and LoWrd macros for efficiency. */
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LoWrd(aLong) ((aLong) & 0xFFFF)
-
- /* Define TopLeft and BotRight macros for convenience. Notice the implicit
- dependency on the ordering of fields within a Rect */
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
- extern void _DataInit();
-
- #pragma segment Main
- main()
- {
- UnloadSeg((Ptr) _DataInit); /* note that _DataInit must not be in Main! */
-
- MaxApplZone(); /* expand the heap so code segments load at the top */
-
- Initialize(); /* initialize the program */
- UnloadSeg((Ptr) Initialize); /* note that Initialize must not be in Main! */
-
- EventLoop(); /* call the main event loop */
- }
-
-
- #pragma segment Main
- void EventLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- EventRecord event;
- Point mouse;
-
- cursorRgn = NewRgn(); /* we’ll pass WNE an empty region the 1st time thru */
- do {
- GetGlobalMouse(&mouse);
- AdjustCursor(mouse, cursorRgn);
- (void) ThreadBeginCritical();
- gotEvent = DhrystoneDone;
- (void) ThreadEndCritical();
- if (gotEvent)
- {
- Str255 run;
- Str255 result;
- short typ;
- Handle item;
- Rect rect;
- GrafPtr savePort;
-
- if (DhrystoneCount == 1)
- {
- Str255 s;
- GetIndString(&s, kDhrystoneString, 1);
- GetDItem(DhrystoneDialog, kMessageItem, &typ, &item, &rect);
- SetIText(item, s);
- }
-
- NumToString(DhrystoneCount, run);
- sprintf((char*)result, "%f", Dhrystones_Per_Second);
- c2pstr(result);
- ParamText(run, result, nil, nil);
- GetPort(&savePort);
- SetPort(DhrystoneDialog);
- GetDItem(DhrystoneDialog, kMessageItem, &typ, &item, &rect);
- InvalRect(&rect);
- SetPort(savePort);
- DhrystoneDone = false;
- DhrystoneCount += 1;
- (void) SetThreadState(gDhrystoneThreadID, kReadyThreadState, kNoThreadID);
- }
-
- gotEvent = WaitNextEvent(everyEvent, &event, 0, cursorRgn);
- if (gotEvent == false)
- (void) YieldToAnyThread();
-
- if ( gotEvent ) {
- /* make sure we have the right cursor before handling the event */
- AdjustCursor(event.where, cursorRgn);
- DoEvent(&event);
- }
- } while ( true ); /* loop forever; we quit via ExitToShell */
- } /*EventLoop*/
-
-
- #pragma segment Main
- void DoEvent(event)
- EventRecord *event;
- {
- short part, err, dummyitem;
- WindowPtr window;
- Boolean hit;
- char key;
- Point aPoint;
- DialogPtr dummydialogptr;
-
- if ( event->what != keyDown && event->what != autoKey && IsDialogEvent(event) )
- (void)DialogSelect(event, &dummydialogptr, &dummyitem);
- else
- switch ( event->what ) {
- case mouseDown:
- part = FindWindow(event->where, &window);
- switch ( part ) {
- case inMenuBar: /* process a mouse menu command (if any) */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow: /* let the system handle the mouseDown */
- SystemClick(event, window);
- break;
- case inContent:
- if ( window != FrontWindow() ) {
- SelectWindow(window);
- /*DoEvent(event);*/ /* use this line for "do first click" */
- } else
- DoContentClick(window);
- break;
- case inDrag: /* pass screenBits.bounds to get all gDevices */
- DragWindow(window, event->where, &qd.screenBits.bounds);
- break;
- case inGrow:
- break;
- case inGoAway:
- DoCloseWindow(window);
- break;
- case inZoomIn:
- case inZoomOut:
- hit = TrackBox(window, event->where, part);
- if ( hit ) {
- SetPort(window); /* the window must be the current port... */
- EraseRect(&window->portRect); /* because of a bug in ZoomWindow */
- ZoomWindow(window, part, true); /* note that we invalidate and erase... */
- InvalRect(&window->portRect); /* to make things look better on-screen */
- }
- break;
- }
- break;
- case keyDown:
- case autoKey: /* check for menukey equivalents */
- key = event->message & charCodeMask;
- if ( event->modifiers & cmdKey ) /* Command key down */
- if ( event->what == keyDown ) {
- AdjustMenus(); /* enable/disable/check menu items properly */
- DoMenuCommand(MenuKey(key));
- }
- break;
- case activateEvt:
- DoActivate((WindowPtr) event->message, (event->modifiers & activeFlag) != 0);
- break;
- case updateEvt:
- DoUpdate((WindowPtr) event->message);
- break;
- case diskEvt:
- if ( HiWord(event->message) != noErr ) {
- SetPt(&aPoint, kDILeft, kDITop);
- err = DIBadMount(aPoint, event->message);
- }
- break;
- case kOSEvent:
- switch ((event->message >> 24) & 0x0FF) { /* high byte of message */
- case kSuspendResumeMessage: /* suspend/resume is also an activate/deactivate */
- gInBackground = (event->message & kResumeMask) == 0;
- DoActivate(FrontWindow(), !gInBackground);
- break;
- }
- break;
- }
- } /*DoEvent*/
-
-
- #pragma segment Main
- void AdjustCursor(mouse,region)
- Point mouse;
- RgnHandle region;
- {
- WindowPtr window;
- RgnHandle arrowRgn;
- RgnHandle plusRgn;
- Rect globalPortRect;
-
- window = FrontWindow(); /* we only adjust the cursor when we are in front */
- if ( (! gInBackground) && (! IsDAWindow(window)) ) {
- /* calculate regions for different cursor shapes */
- arrowRgn = NewRgn();
- plusRgn = NewRgn();
-
- /* start with a big, big rectangular region */
- SetRectRgn(arrowRgn, kExtremeNeg, kExtremeNeg, kExtremePos, kExtremePos);
-
- /* calculate plusRgn */
- if ( IsAppWindow(window) ) {
- SetPort(window); /* make a global version of the viewRect */
- SetOrigin(-window->portBits.bounds.left, -window->portBits.bounds.top);
- globalPortRect = window->portRect;
- RectRgn(plusRgn, &globalPortRect);
- SectRgn(plusRgn, window->visRgn, plusRgn);
- SetOrigin(0, 0);
- }
-
- /* subtract other regions from arrowRgn */
- DiffRgn(arrowRgn, plusRgn, arrowRgn);
-
- /* change the cursor and the region parameter */
- if ( PtInRgn(mouse, plusRgn) ) {
- SetCursor(*GetCursor(plusCursor));
- CopyRgn(plusRgn, region);
- } else {
- SetCursor(&qd.arrow);
- CopyRgn(arrowRgn, region);
- }
-
- /* get rid of our local regions */
- DisposeRgn(arrowRgn);
- DisposeRgn(plusRgn);
- }
- } /*AdjustCursor*/
-
-
- #pragma segment Main
- void GetGlobalMouse(mouse)
- Point *mouse;
- {
- EventRecord event;
-
- OSEventAvail(kNoEvents, &event); /* we aren't interested in any events */
- *mouse = event.where; /* just the mouse position */
- } /*GetGlobalMouse*/
-
-
- #pragma segment Main
- void DoUpdate(window)
- WindowPtr window;
- {
- if ( IsAppWindow(window) ) {
- BeginUpdate(window); /* this sets up the visRgn */
- if ( ! EmptyRgn(window->visRgn) ) /* draw if updating needs to be done */
- DrawWindow(window);
- EndUpdate(window);
- }
- } /*DoUpdate*/
-
-
- #pragma segment Main
- void DoActivate(window, becomingActive)
- WindowPtr window;
- Boolean becomingActive;
- {
- if ( IsAppWindow(window) ) {
- if ( becomingActive )
- /* do whatever you need to at activation */ ;
- else
- /* do whatever you need to at deactivation */ ;
- }
- } /*DoActivate*/
-
-
- #pragma segment Main
- void DoContentClick(window)
- WindowPtr window;
- {
- SetLight(window, ! ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped);
- } /*DoContentClick*/
-
-
- #pragma segment Main
- void DrawWindow(window)
- WindowPtr window;
- {
- SetPort(window);
-
- EraseRect(&window->portRect); /* clear out any garbage that may linger */
- if ( ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ) /* draw a red (or white) stop light */
- ForeColor(redColor);
- else
- ForeColor(whiteColor);
- PaintOval(&gStopRect);
- ForeColor(blackColor);
- FrameOval(&gStopRect);
- if ( ! ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ) /* draw a green (or white) go light */
- ForeColor(greenColor);
- else
- ForeColor(whiteColor);
- PaintOval(&gGoRect);
- ForeColor(blackColor);
- FrameOval(&gGoRect);
- } /*DrawWindow*/
-
-
- #pragma segment Main
- void AdjustMenus()
- {
- WindowPtr window;
- MenuHandle menu;
-
- window = FrontWindow();
-
- menu = GetMHandle(mFile);
- EnableItem(menu, iNew);
- if (window != nil)
- EnableItem(menu, iClose);
-
- menu = GetMHandle(mEdit);
- if ( IsDAWindow(window) ) { /* a desk accessory might need the edit menu… */
- EnableItem(menu, iUndo);
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- EnableItem(menu, iPaste);
- } else { /* …but we don’t use it */
- DisableItem(menu, iUndo);
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- DisableItem(menu, iPaste);
- }
-
- } /*AdjustMenus*/
-
-
- #pragma segment Main
- void DoMenuCommand(menuResult)
- long menuResult;
- {
- short menuID; /* the resource ID of the selected menu */
- short menuItem; /* the item number of the selected menu */
- short itemHit;
- Str255 daName;
- short daRefNum;
- Boolean handledByDA;
-
- menuID = HiWord(menuResult); /* use macros for efficiency to... */
- menuItem = LoWord(menuResult); /* get menu item number and menu number */
- switch ( menuID ) {
- case mApple:
- switch ( menuItem ) {
- case iAbout: /* bring up alert for About */
- itemHit = Alert(rAboutAlert, nil);
- break;
- default: /* all non-About items in this menu are DAs */
- /* type Str255 is an array in MPW 3 */
- GetItem(GetMHandle(mApple), menuItem, daName);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
- case mFile:
- switch ( menuItem ) {
- case iNew:
- DoNewWindow();
- break;
- case iClose:
- DoCloseWindow(FrontWindow());
- break;
- case iQuit:
- Terminate();
- break;
- }
- break;
- case mEdit: /* call SystemEdit for DA editing & MultiFinder */
- handledByDA = SystemEdit(menuItem-1); /* since we don’t do any Editing */
- break;
- case mLight:
- switch ( menuItem ) {
- case iStop:
- SetLight(FrontWindow(), true);
- break;
- case iGo:
- SetLight(FrontWindow(), false);
- break;
- }
- break;
- }
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- } /*DoMenuCommand*/
-
- /* Change the setting of the light. */
-
- #pragma segment Main
- void SetLight( window, newStopped )
- WindowPtr window;
- Boolean newStopped;
- {
- if ( newStopped != ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped ) {
- ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->stopped = newStopped;
- SetPort(window);
- InvalRect(&window->portRect);
- }
- } /*SetLight*/
-
- #pragma segment Main
- void
- DoNewWindow(void)
- {
- WindowPtr window, tempWindow; // temp window so we can dump it if NewWindow fails
- OurWindowInfoRecPtr windowInfoPtr;
- ThreadID theNewThread;
-
- if ( (window = tempWindow = (WindowPtr) NewPtr(sizeof(WindowRecord))) == nil ) // get window storage
- goto ErrorHandler2;
-
- if ( (windowInfoPtr = (OurWindowInfoRecPtr) NewPtr(sizeof(OurWindowInfoRec))) == nil ) // get refCon storage
- goto ErrorHandler2;
-
- MemClear(windowInfoPtr, sizeof(OurWindowInfoRec)); // Lazy way to init the fields
- windowInfoPtr->threadID = kNoThreadID; // init the thread ID
-
- if ((window = GetNewWindow(rWindow, (Ptr) window, (WindowPtr) -1)) == nil) // get the window
- goto ErrorHandler1;
-
- ((WindowPeek) window)->refCon = windowInfoPtr; // assign it to the window
-
- if (NewThread(kCooperativeThread, WindowThread, (void *) window, 0, (kUsePremadeThread), nil, &theNewThread) != noErr)
- goto ErrorHandler1;
- windowInfoPtr->threadID = theNewThread; // assign real thread ID
-
- return;
-
- ErrorHandler1:
- CloseWindow(tempWindow);
- ErrorHandler2:
- AlertUserContinue(eCommandFailed);
- }
-
- void
- DoCloseWindow(WindowPtr window)
- {
- if ( IsDAWindow(window) )
- CloseDeskAcc(((WindowPeek) window)->windowKind);
- else if ( IsAppWindow(window) )
- ((OurWindowInfoRecPtr) (((WindowPeek) window)->refCon))->timeToClose = true;
- } /*DoCloseWindow*/
-
- #define TICKS (*((unsigned long *) 0x16A))
-
- pascal void *
- WindowThread(void *myWindow)
- {
- WindowPtr window;
- unsigned long baseTicks, currTicks;
- Boolean toggle;
- OurWindowInfoRecPtr windowInfoPtr;
-
- window = (WindowPtr) myWindow; // get the window
- windowInfoPtr = (OurWindowInfoRecPtr) (((WindowPeek) window)->refCon); // get the data (inited by DoNewWindow)
-
- baseTicks = TICKS;
- toggle = false;
- for (;;)
- {
- if (windowInfoPtr->timeToClose)
- {
- CloseWindow(window);
- (void) DisposeThread(kCurrentThreadID, 0, true); // and the lights go out...
- }
-
- currTicks = TICKS;
- if (baseTicks + 60 <= currTicks)
- {
- SetLight(window, toggle);
- toggle = ! toggle;
- baseTicks = currTicks;
- }
-
- (void) YieldToAnyThread();
- }
-
- return((void *) 'Wind');
- }
-
- #pragma segment Main
- void Terminate()
- {
- WindowPtr aWindow;
- OSErr myErr;
-
- while ((aWindow = FrontWindow()) != nil)
- {
- if (((WindowPeek) aWindow)->windowKind == dialogKind)
- CloseDialog((DialogPtr) aWindow);
- else
- {
- DoCloseWindow(aWindow);
- myErr = YieldToThread(((OurWindowInfoRecPtr) (((WindowPeek) aWindow)->refCon))->threadID);
- if (myErr) DebugStr ("\p Error from YieldToThread in Terminate()");
- }
- }
-
- ExitToShell();
- } /*Terminate*/
-
-
- #pragma segment Initialize
- void Initialize()
- {
- Handle menuBar;
- EventRecord event;
- short count;
-
- gInBackground = false;
- (void) CreateThreadPool(kCooperativeThread, 5, 0);
- (void) CreateThreadPool(kPreemptiveThread, 1, 0);
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- for (count = 1; count <= 3; count++)
- EventAvail(everyEvent, &event);
-
- SysEnvirons(kSysEnvironsVersion, &gMac);
-
- /* Make sure that the machine has at least 128K ROMs. If it doesn't, exit. */
-
- if (gMac.machineType < 0) AlertUser();
-
- menuBar = GetNewMBar(rMenuBar); /* read menus into menu bar */
- if ( menuBar == nil ) AlertUser();
- SetMenuBar(menuBar); /* install menus */
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR'); /* add DA names to Apple menu */
- DrawMenuBar();
-
- if ( !GoGetRect(rStopRect, &gStopRect) )
- AlertUser(); /* the stop light rectangle */
- if ( !GoGetRect(rGoRect, &gGoRect) )
- AlertUser(); /* the go light rectangle */
-
- DhrystoneDialog = GetNewDialog(kDhrystoneDLOG, nil, (WindowPtr)-1);
-
- DhrystoneCount = 1;
- DhrystoneDone = false;
- if (NewThread(kPreemptiveThread, DhrystoneThread, (void *) 0, 0, (kUsePremadeThread), nil, &gDhrystoneThreadID) != noErr)
- AlertUser();
-
- } /*Initialize*/
-
-
- #pragma segment Initialize
- Boolean GoGetRect(rectID,theRect)
- short rectID;
- Rect *theRect;
- {
- Handle resource;
-
- resource = GetResource('RECT', rectID);
- if ( resource != nil ) {
- *theRect = **((Rect**) resource);
- return true;
- }
- else
- return false;
- } /* GoGetRect */
-
-
- #pragma segment Main
- Boolean IsAppWindow(window)
- WindowPtr window;
- {
- short windowKind;
-
- if ( window == nil )
- return false;
- else {
- windowKind = ((WindowPeek) window)->windowKind;
- return (windowKind == userKind);
- }
- } /*IsAppWindow*/
-
-
- #pragma segment Main
- Boolean IsDAWindow(window)
- WindowPtr window;
- {
- if ( window == nil )
- return false;
- else /* DA windows have negative windowKinds */
- return ((WindowPeek) window)->windowKind < 0;
- } /*IsDAWindow*/
-
-
- #pragma segment Initialize
- Boolean TrapAvailable(tNumber,tType)
- short tNumber;
- TrapType tType;
- {
- if ( ( tType == ToolTrap ) &&
- ( gMac.machineType > envMachUnknown ) &&
- ( gMac.machineType < envMacII ) ) { /* it's a 512KE, Plus, or SE */
- tNumber = tNumber & 0x03FF;
- if ( tNumber > 0x01FF ) /* which means the tool traps */
- tNumber = _Unimplemented; /* only go to 0x01FF */
- }
- return NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented);
- } /*TrapAvailable*/
-
-
- #pragma segment Main
-
- /* -----------------------------------------------------------------------------
- *
- * Dhrystone.
- *
- * -----------------------------------------------------------------------------*/
-
- pascal void *
- DhrystoneThread(void *threadParam)
- {
- #pragma unused (threadParam)
- for (;;)
- {
- Dhrystone();
- (void) ThreadBeginCritical();
- DhrystoneDone = true;
- (void) ThreadEndCritical();
- (void) SetThreadState(kCurrentThreadID, kStoppedThreadState, kNoThreadID);
- }
-
- (void) DisposeThread(kCurrentThreadID, 0, true);
- return((void *) 'Dhry');
- }
-
- void
- Dhrystone(void)
- {
- One_Fifty Int_1_Loc;
- register One_Fifty Int_2_Loc;
- One_Fifty Int_3_Loc;
- register char Ch_Index;
- Enumeration Enum_Loc;
- Str_30 Str_1_Loc;
- Str_30 Str_2_Loc;
- register int Run_Index;
- register int Number_Of_Runs;
- Rec_Type fake_malloc1;
- Rec_Type fake_malloc2;
-
- unsigned long Begin_Time, End_Time, User_Time;
-
- /* Initializations */
-
- Next_Ptr_Glob = (Rec_Pointer) &fake_malloc1;
- Ptr_Glob = (Rec_Pointer) &fake_malloc2;
-
- Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
- Ptr_Glob->Discr = Ident_1;
- Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
- Ptr_Glob->variant.var_1.Int_Comp = 40;
- strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING");
- strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
-
- /* Was missing in published program. Without this statement, */
- /* Arr_2_Glob [8][7] would have an undefined value. */
- /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
- /* overflow may occur for this array element. */
- Arr_2_Glob [8][7] = 10;
-
- Number_Of_Runs = 100000;
-
- /*********************/
- /* Start timed tests */
- /*********************/
-
- Begin_Time = TICKS;
- for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
- {
- Proc_5();
- Proc_4();
-
- /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
- Int_1_Loc = 2;
- Int_2_Loc = 3;
- strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
- Enum_Loc = Ident_2;
- Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
- /* Bool_Glob == 1 */
-
- while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
- {
- Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
- /* Int_3_Loc == 7 */
- Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
- /* Int_3_Loc == 7 */
- Int_1_Loc += 1;
- } /* while */
-
- /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
- Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
-
- /* Int_Glob == 5 */
- Proc_1 (Ptr_Glob);
- for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index) /* loop executed twice */
- {
- if (Enum_Loc == Func_1 (Ch_Index, 'C')) /* then, not executed */
- {
- Proc_6 (Ident_1, &Enum_Loc);
- strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
- Int_2_Loc = Run_Index;
- Int_Glob = Run_Index;
- }
- }
-
- /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
- Int_2_Loc = Int_2_Loc * Int_1_Loc;
- Int_1_Loc = Int_2_Loc / Int_3_Loc;
- Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
-
- /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
- Proc_2 (&Int_1_Loc);
-
- /* Int_1_Loc == 5 */
-
- } /* loop "for Run_Index" */
-
- /********************/
- /* Stop timed tests */
- /********************/
-
- End_Time = TICKS;
- User_Time = End_Time - Begin_Time;
-
- if (User_Time < Too_Small_Time)
- Debugger();
- else
- {
- Microseconds = (float) User_Time * Mic_secs_Per_Second / ((float) 60 * ((float) Number_Of_Runs));
- Dhrystones_Per_Second = ((float) 60 * (float) Number_Of_Runs) / (float) User_Time;
- }
-
- }
-
- /* executed once */
- void
- Proc_1(register Rec_Pointer Ptr_Val_Par)
- {
- register Rec_Pointer Next_Record;
-
- Next_Record = Ptr_Val_Par->Ptr_Comp; /* == Ptr_Glob_Next */
-
- /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
- /* corresponds to "rename" in Ada, "with" in Pascal */
-
- *Ptr_Val_Par->Ptr_Comp = *Ptr_Glob;
- Ptr_Val_Par->variant.var_1.Int_Comp = 5;
- Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp;
- Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
- Proc_3 (&Next_Record->Ptr_Comp);
- /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp == Ptr_Glob->Ptr_Comp */
-
- if (Next_Record->Discr == Ident_1) /* then, executed */
- {
- Next_Record->variant.var_1.Int_Comp = 6;
- Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp);
- Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
- Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp);
- }
- else /* not executed */
- *Ptr_Val_Par = *Ptr_Val_Par->Ptr_Comp;
- } /* Proc_1 */
-
-
- /* executed once */
- /* *Int_Par_Ref == 1, becomes 4 */
- void
- Proc_2(One_Fifty *Int_Par_Ref)
- {
- One_Fifty Int_Loc;
- Enumeration Enum_Loc;
-
- Int_Loc = *Int_Par_Ref + 10;
- do /* executed once */
- if (Ch_1_Glob == 'A') /* then, executed */
- {
- Int_Loc -= 1;
- *Int_Par_Ref = Int_Loc - Int_Glob;
- Enum_Loc = Ident_1;
- } /* if */
-
- while (Enum_Loc != Ident_1); /* true */
- } /* Proc_2 */
-
-
- /* executed once */
- /* Ptr_Ref_Par becomes Ptr_Glob */
- void
- Proc_3(Rec_Pointer *Ptr_Ref_Par)
- {
- if (Ptr_Glob != nil) /* then, executed */
- *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
- Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
- } /* Proc_3 */
-
-
- /* executed once */
- void
- Proc_4(void)
- {
- Boolean Bool_Loc;
-
- Bool_Loc = Ch_1_Glob == 'A';
- Bool_Glob = Bool_Loc | Bool_Glob;
- Ch_2_Glob = 'B';
- } /* Proc_4 */
-
-
- /* executed once */
- void
- Proc_5(void)
- {
- Ch_1_Glob = 'A';
- Bool_Glob = false;
- } /* Proc_5 */
-
- /* executed once */
- /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
- void
- Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par)
- {
- *Enum_Ref_Par = Enum_Val_Par;
- if (! Func_3 (Enum_Val_Par)) /* then, not executed */
- *Enum_Ref_Par = Ident_4;
- switch (Enum_Val_Par)
- {
- case Ident_1:
- *Enum_Ref_Par = Ident_1;
- break;
- case Ident_2:
- if (Int_Glob > 100)
- *Enum_Ref_Par = Ident_1;
- else
- *Enum_Ref_Par = Ident_4;
- break;
- case Ident_3: /* executed */
- *Enum_Ref_Par = Ident_2;
- break;
- case Ident_4: break;
- case Ident_5:
- *Enum_Ref_Par = Ident_3;
- break;
- } /* switch */
- } /* Proc_6 */
-
-
- /* executed three times */
- /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
- /* Int_Par_Ref becomes 7 */
- /* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
- /* Int_Par_Ref becomes 17 */
- /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
- /* Int_Par_Ref becomes 18 */
- void
- Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref)
- {
- One_Fifty Int_Loc;
-
- Int_Loc = Int_1_Par_Val + 2;
- *Int_Par_Ref = Int_2_Par_Val + Int_Loc;
- } /* Proc_7 */
-
-
- /* executed once */
- /* Int_Par_Val_1 == 3 */
- /* Int_Par_Val_2 == 7 */
- void
- Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val)
- {
- register One_Fifty Int_Index;
- register One_Fifty Int_Loc;
-
- Int_Loc = Int_1_Par_Val + 5;
- Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
- Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
- Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
- for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
- Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
- Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
- Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
- Int_Glob = 5;
- } /* Proc_8 */
-
-
- /* executed three times */
- /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
- /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
- /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
- Enumeration
- Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val)
- {
- Capital_Letter Ch_1_Loc;
- Capital_Letter Ch_2_Loc;
-
- Ch_1_Loc = Ch_1_Par_Val;
- Ch_2_Loc = Ch_1_Loc;
- if (Ch_2_Loc != Ch_2_Par_Val) /* then, executed */
- return (Ident_1);
- else /* not executed */
- {
- Ch_1_Glob = Ch_1_Loc;
- return (Ident_2);
- }
- } /* Func_1 */
-
-
- /* executed once */
- /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
- /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
- Boolean
- Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref)
- {
- register One_Thirty Int_Loc;
- Capital_Letter Ch_Loc;
-
- Int_Loc = 2;
- while (Int_Loc <= 2) /* loop body executed once */
- {
- if (Func_1 (Str_1_Par_Ref[Int_Loc], Str_2_Par_Ref[Int_Loc+1]) == Ident_1) /* then, executed */
- {
- Ch_Loc = 'A';
- Int_Loc += 1;
- }
- }
-
- if (Ch_Loc >= 'W' && Ch_Loc < 'Z') /* then, not executed */
- Int_Loc = 7;
-
- if (Ch_Loc == 'R') /* then, not executed */
- return (true);
- else /* executed */
- {
- if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
- /* then, not executed */
- {
- Int_Loc += 7;
- Int_Glob = Int_Loc;
- return (true);
- }
- else /* executed */
- return (false);
- } /* if Ch_Loc */
- } /* Func_2 */
-
-
- /* Func_3. Whether Enum_Par_Val == Ident_3 */
- Boolean
- Func_3 (Enumeration Enum_Par_Val)
- {
- Enumeration Enum_Loc;
-
- Enum_Loc = Enum_Par_Val;
- return (Enum_Loc == Ident_3);
- } /* Func_3 */
-
- /* -----------------------------------------------------------------------------
- *
- * Utility routines.
- *
- * -----------------------------------------------------------------------------*/
-
- void
- AlertUserContinue(short error)
- {
- Str255 message;
-
- SetCursor(&qd.arrow);
- GetIndString(message, kErrStrings, error);
- ParamText(message, "", "", "");
- (void) Alert(rUserAlert, nil);
- }
-
- void AlertUser()
- {
- short itemHit;
-
- SetCursor(&qd.arrow);
- itemHit = Alert(rUserAlert, nil);
- ExitToShell();
- } /* AlertUser */
-
- /* MemClear. Two-bit routine to clear 'bytes' bytes starting at *'ptr' */
- void
- MemClear(register void *ptr, register unsigned long bytes)
- {
- do
- {
- *((char *) ptr)++ = (char) 0x00;
- }
- while (--bytes != 0);
- }
-